package com.chb.myWeather;

import java.io.IOException;

import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class MyReducer extends Reducer<MyKey, DoubleWritable, Text, NullWritable>{
	@Override
	protected void reduce(MyKey key, Iterable<DoubleWritable> values, Context context)
			throws IOException, InterruptedException {
		//由于分组是按照月份，自定义排序是按照温度降序
		//所以shuffler执行完的数据，是一个月数据，按照温度的降序排序，
		//所以我们只要获取前三个值，就是一个月份的最高三个温度
		int num = 0;
		for (DoubleWritable dw : values) {
			String msg = key.getYear()+"年"+key.getMonth()+"月"+"\t"+dw.toString();
			//写数据
			context.write(new Text(msg), null);
			if (num==3) {
				break;
			}
		}
	}
}
